package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.entity.ReqPage;
import com.fwtai.service.api.ApiGoodsService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 商品
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-04 17:45:50
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@Api(tags = "商品",description = "token选填")
@RequestMapping(ConfigFile.guest_v10 +"goods")
public class GoodsController{

  private final ApiGoodsService apiGoodsService;

  public GoodsController(final ApiGoodsService apiGoodsService){
    this.apiGoodsService = apiGoodsService;
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取单条的商品详细信息", notes = "通过商品kid获取商品详细信息")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "id传值：当type=1时传门店商品表的主键kid;当type=2传区级代理商品表的kid;当type=3总公司的商品kid", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "type", value = "查看类型:1=直营门店的商品详情;2=区级代理的商品详情;3=总公司的商品详情", dataType = "int", paramType = "query", required = true)
  })
  @GetMapping("/queryById")
  public void queryById(final Long id,final Integer type,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.queryById(id,type),response);
  }

  @ApiOperation(value = "获取总公司商品列表,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listDataPage")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query", required = false),
  })
  public void listDataPage(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listData(request),response);
  }

  @ApiOperation(value = "获取获取区级[合伙人]的商品列表,暂时用不到,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listPagePartner")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "provinceId", value = "省级id", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "cityId", value = "市级id", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "countyId", value = "区县id", dataType = "String", paramType = "query", required = false)
  })
  public void listPagePartner(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listPagePartner(request),response);
  }

  //区代设置商品优先级
  @ApiOperation(value = "区代设置商品优先级", notes = "区代设置商品优先级")
  @PostMapping("/addPriorityProxy")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "区代商品kid", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "String", paramType = "query", required = true)
  })
  public void addPriorityProxy(final String kid,final String goodsId,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.addPriorityProxy(kid,goodsId),response);
  }

  @ApiOperation(value = "门店设置商品优先级", notes = "门店设置商品优先级")
  @PostMapping("/addPriorityStore")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "门店商品kid", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "String", paramType = "query", required = true)
  })
  public void addPriorityStore(final String kid,final String goodsId,final String storeId,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.addPriorityStore(kid,goodsId,storeId),response);
  }

  //区代的商品库
  @ApiOperation(value = "区代的商品库,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listInventoryProxy")
  public void listInventoryProxy(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listInventoryProxy(request),response);
  }

  //门店的商品库
  @ApiOperation(value = "门店的商品库,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listInventoryStore")
  public void listInventoryStore(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listInventoryStore(request),response);
  }

  @ApiOperation(value = "区代的商品优惠券列表,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listCouponProxy")
  @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "String", paramType = "query", required = true)
  public void listCouponProxy(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listCouponProxy(request),response);
  }

  @ApiOperation(value = "门店的商品优惠券列表,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listCouponStore")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "storeId", value = "门店id", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "String", paramType = "query", required = true)
  })
  public void listCouponStore(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.listCouponStore(request),response);
  }

  @ApiOperation(value = "扫码查看商品信息", notes = "扫码查看商品信息,<span class='danger'>前端仅需判断查看次数是否为0时是首次查看并标记不同的颜色,如是0时用绿色标识,否则用其他颜色;check_time是首次查看时间</span>")
  @GetMapping("/getGoods")
  @ApiImplicitParam(name = "code", value = "防伪码", dataType = "String", paramType = "query", required = true)
  public void getGoods(final String code,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsService.getGoods(code),response);
  }
}